package edu.arizona.sista.learn.model.motion;

import java.util.ArrayList;
import java.util.List;

import edu.arizona.sista.learn.model.Interval;
import edu.arizona.sista.learn.model.displaying.Event;
import edu.arizona.sista.learn.model.holding.Person;

public class MovementEvent extends Event{
	public Person _doer;
	public List<Event> _subEvents;
	
	public MovementEvent(Person p, Interval time) {
		super(time);
		_doer = p;
		_subEvents = new ArrayList<Event>();
	}

	public String toString() {
		String s1 = "isa(" + getVariableName() + ", MovementEvent)\n";
		String s2 = "perfomedBy(" + getVariableName() + ", " + _doer.getVariableName() + ")\n";
		String t = "t_"  + _time.start() + "-" + _time.end();
		String s3 = "temporalExtent(" + getVariableName() + ", " + t + ")\n";
		StringBuffer sb = new StringBuffer();
		for (Event e: _subEvents) sb.append("subEvents(" + getVariableName() + ", " + e.getVariableName() + ")\n");
		return s1 + s2 + s3 + sb.toString();
	}

	public void addSubEvent(RectilinearTrajectory e) {
		_subEvents.add(e);
		adjustBounds(e._time);
	}

	private void adjustBounds(Interval time) {
		if (time.start() < _time.start()) _time.setStart(time.start());
		if (time.end() > _time.end()) _time.setEnd(time.end());
	}
}
